package com.wing.sell.model.entity;

import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 销售订单表
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sel_order")
public class Order extends BaseEntity<Order> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum OrderRoot implements IEnum<Integer> {

        /**
         * 询价订单一步步转化的
         */
        enquiry(0,"询价转化"),
        /**
         * 在正式订单页面直接添加的
         */
        formal(1,"直接添加的正式订单");

        private int code;
        private String desc;

        OrderRoot(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }




    public enum OrderSource implements IEnum<Integer> {

        /**
        * 自主录入/员工录入
        */
        staff(0,"自主录入/员工录入"),
        /**
        * 云端制造/平台指派
        */
        platform(1,"云端制造/平台指派"),
        /**
        * 渠道录入/代理商录入
        */
        agent(2,"渠道录入/代理商录入"),
        /**
        * 云端智采/客户直接委派
        */
        customer(3,"云端智采/客户直接委派");

        private int code;
        private String desc;

        OrderSource(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static OrderSource jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (OrderSource item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    public enum OrderType implements IEnum<Integer> {

        /**
        * 打样订单
        */
        proff(0,"打样订单"),
        /**
        * 试产订单
        */
        trial(1,"试产订单"),
        /**
        * 量产订单
        */
        mass(2,"量产订单");

        private int code;
        private String desc;

        OrderType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static OrderType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (OrderType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    public enum Status implements IEnum<Integer> {

        /**
        * 待提交
        */
        pending(0,"待提交"),
        /**
        * 待受理
        */
        accept(1,"待受理"),
        /**
        * 待评审
        */
        review(2,"待评审"),
        /**
        * 不接单
        */
        refuse(3,"不接单"),
        /**
        * 待报价
        */
        offer(4,"待报价"),
        /**
        * 待签约
        */
        tosign(5,"待签约"),
        /**
        * 已签约
        */
        signed(6,"已签约"),
        /**
        * 完成
        */
        finish(7,"已完成"),
        /**
        * 关闭
        */
        over(8,"已关闭");

        private int code;
        private String desc;

        Status(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 是否签约
     */
    private String hasSign;

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 订单编号
     */
    private String code;

    /**
     * 订单编号用
     */
    private Integer day;

    /**
     * 订单编号用
     */
    private Integer no;

    /**
     * 订单来源
     */
    private OrderSource orderSource;

    /**
    * 订单来源描述
    */
    @TableField(exist = false)
    private String orderSourceDesc;

    public String getOrderSourceDesc() {
        return orderSource == null ? null : orderSource.getDesc();
    }

    /**
     * 客户ID
     */
    private Long customerId;

    /**
     * 客户联系人ID
     */
    private String customerContactsId;

    /**
     * 订单类型
     */
    private OrderType orderType;

    /**
    * 订单类型描述
    */
    @TableField(exist = false)
    private String orderTypeDesc;

    public String getOrderTypeDesc() {
        return orderType == null ? null : orderType.getDesc();
    }

    /**
     * 订单状态
     */
    private Status status;

    /**
    * 订单状态描述
    */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        return status == null ? null : status.getDesc();
    }
    /**
     * 订单区分
     */
    private OrderRoot orderRoot;

    /**
     * 订单区分描述
     */
    @TableField(exist = false)
    private String orderRootDesc;

    public String getOrderRootDesc() {
        return orderRoot == null ? null : orderRoot.getDesc();
    }
    /**
     * 产品数量
     */
    private Integer proQuantity;

    /**
    * 交货时间
    */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deliveryTime;

    /**
     * 所属渠道ID
     */
    private Long channelId;


    /**
     * 所属合同ID
     */
    private Long contractId;

    /**
     * 询价审核人ID
     */
    private Long checkerId;
    /**
     * 询价审核人名称
     */
    private String checkerName;

    /**
    * 报价截止时间
    */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime offerEndTime;

    /**
     * 订单总金额
     */
    private BigDecimal amount;

    /**
     * 排产状态
     */
    private String pcStatus;

    /**
     * 排产状态名称
     */
    @TableField(exist = false)
    private String pcStatusName;

    /** 订单包含的产品
     */
    @TableField(exist = false)
    private List<OrderPro> orderProList = new ArrayList<OrderPro>();
    /** 订单包含的报价单
     */
    @TableField(exist = false)
    private List<OrderOffer> orderOfferList = new ArrayList<OrderOffer>();
}
